package com.project.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;



/**
 * 字符串加密
 * @author weimingsen
 *
 */
public class EncryptString {
	
	public static String MD5(String str){
		return encoder(str);
	} 
	
    private static String encoder(String sourceStr) {
        String result = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(sourceStr.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            result = buf.toString();
        } catch (NoSuchAlgorithmException e) {
            System.out.println(e);
        }
        return result;
    }
    
    /**
     * RSA加密
     * @param str
     * @return
     * @throws Exception
     *//*
    public String rsaEncrypt(String str) throws Exception{
    	return rsaEncrypt(configBean.getTonglianAlias(), configBean.getTonglianPath(), configBean.getTonglianPwd(),str);
    }
    
    *//**
     * RSA解密
     * @param str
     * @return
     * @throws Exception
     *//*
    public String rsaDecrypt(String str) throws Exception{
    	return rsaDecrypt(configBean.getTonglianAlias(), configBean.getTonglianPath(), configBean.getTonglianPwd(),str);
    }*/
    

}
